// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async(event, context) => {
    const {
        value,
        content
    } = event;
    try {
        let msgR = false;
        let imageR = false;
        if (content){
            msgR = await cloud.openapi.security.msgSecCheck({
                content: event.content
            })
        }
        if (value) {
            imageR = await cloud.openapi.security.imgSecCheck({
                media: {
                    header: { 'Content-Type': 'application/octet-stream' },
                    contentType: 'image/png',
                    value: Buffer.from(value)
                }
            })
        }
        return {
            msgR,   //内容检查返回值
            imageR   //图片检查返回值
        };
    } catch (err) {
        return err;
    }
}